package com.lizhen.j2eepattern.servicelocatorpattern;

public class ServiceLocator {
    private static Cache cache = new Cache();

    public ServiceLocator() {
    }

    public static Service getService(String jndiName) {
        Service service = cache.getService(jndiName);
        if (service != null) {
            return service;
        } else {
            InitialContext context = new InitialContext();
            Service service1 = (Service) context.lookup(jndiName);
            cache.addService(service1);
            return service1;
        }
    }
}
